package com.linux.huhx.stringTest;

import org.junit.Test;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by huhx on 2017-05-25.
 */
public class StringTest1 {

    @Test
    public void castTest_1() {
        Object[] objects = new Object[1];
        String[] strings = (String[]) objects;
        System.out.println("hello world" + strings); // [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
    }

    @Test
    public void getGenericType() {
        SubClass subClass = new SubClass();
        subClass.getType();
    }

}

class SuperClass<RR, RS> {
    private Class<RR> requestClass;
    private Class<RS> responseClass;
    public SuperClass() {
        requestClass = (Class<RR>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        responseClass = (Class<RS>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
    }

    public void getType() {
        System.out.println(requestClass.getClass().getName());
        System.out.println(responseClass.getClass().getName());
    }
}

class SubClass extends SuperClass<String, Integer> {

}
